#include <stdio.h>
int seq_search(int array[],int n,int k,int seek_seq[]) {
    for (int i=0;i<n;i++) {
        seek_seq[i]=i;
        if (array[i]==k) {
            return 0;
        }
    }
    return -1;
}//二分查找函数
int bin_search(int array[],int n,int k,int seek_seq[]) {
    int left=0;
    int right=n-1;
    int mid;
    int index=0;
    while (left<=right) {
        mid=(left+right)/2;
        seek_seq[index++]=mid;
        if (array[mid]==k) {
            return 0;
        }else if (array[mid]<k) {
            left=mid+1;
        }else {
            right=mid-1;
        }
    }
    return -1;
}
//以下是测试代码部分
int main() {
    int array[]={1,3,5,7,9};
    int n=sizeof(array)/sizeof(array[0]);
    int k=5;
    int seek_seq1[n];
    int seek_seq2[2];
    //顺序查找测试
    int result_seq=seq_search(array,n,k,seek_seq1);
    if(result_seq==0) {
        printf("顺序查找成功，查找路径序列（下标）：");
        for(int i=0;i<n;i++) {
            printf("%d",seek_seq1[i]);
        }
        printf("\n");
    }
    //二分查找测试
    int result_bin=bin_search(array,n,k,seek_seq2);
    if(result_bin==0) {
        printf("二分查找成功，查找路径序列（下标）：");
        for(int i=0;i<n;i++) {
            printf("%d",seek_seq2[i]);
        }
        printf("\n");
    }else {
        printf("二分查找失败\n");
    }
    return 0;
}